package com.intellagric.controller.module.sys_user;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.SysMenu;
import com.intellagric.pojo.SysUser;
import com.intellagric.service.module.sys_user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Auther: zhy
 * @Date: 2018/10/4
 * @Description: 用户管理接口
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;    //idea工作机制问题，无错误

    /**
     * 添加用户信息
     * @Param sysUser
     * @Param roleId 角色id
     * @Param officeId 机构id
     * @return ResponseMessage
     */
    @RequestMapping("/user/add")
    @ResponseBody
    public ResponseMessage add(SysUser sysUser) {
        //初始化数据
        sysUser.setId(UUID.randomUUID().toString().replace("-",""));
        sysUser.setCreateDate(new Date());
        sysUser.setUpdateDate(new Date());
        return userService.addUser(sysUser);
    }


    /**
     * 删除用户信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/user/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return userService.deleteUser(id);
    }

    /**
     * 修改信息
     * @Param sysUser
     * @return ResponseMessage
     */
    @RequestMapping("/user/edit")
    @ResponseBody
    public ResponseMessage edit(SysUser sysUser) {
        sysUser.setCreateDate(null);//不修改创建时间
        sysUser.setUpdateDate(new Date());
        return userService.editUser(sysUser);
    }

    /**
     * 查询用户信息
     * @Param id
     * @return Object
     */
    @RequestMapping("/user/{id}")
    @ResponseBody
    public SysUser get(@PathVariable String id) {
        return userService.getUserById(id);
    }

    /**
     * 查询用户信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/user/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return userService.getUserList();
    }

    @RequestMapping("/user/page")
    @ResponseBody
    public LayuiDataGridResult query(int page,int row) {
        LayuiDataGridResult userList = userService.getUserList(page,row);
        return userList;
    }
}
